package com.sumainfor.common.utlis;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.sumainfor.common.entity.MoSupplierObject;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * @Author PuaChen
 * @Create 2018-11-16 11:41
 */
public class MoSupplierObjectUtil {

    public static List<MoSupplierObject> convertJsonToList(String json) {
        if (StringUtils.isBlank(json)) {
            return Lists.newArrayList();
        }
        List<MoSupplierObject> list = JSONObject.parseArray(json, MoSupplierObject.class);
        return list;
    }


    public static String toJson(List<MoSupplierObject> list) {
        return JSONObject.toJSONString(list);
    }

    public static MoSupplierObject selectSupplierById(List<MoSupplierObject> list, String id) {
        for (MoSupplierObject object : list) {
            if (object.getSupplierId().equals(id)) {
                return object;
            }
        }
        return null;
    }
}
